package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.SeekBar;

import com.blankj.utilcode.util.ImageUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.vilyever.drawingview.DrawingView;
import com.vilyever.drawingview.brush.drawing.CircleBrush;
import com.vilyever.drawingview.brush.drawing.EllipseBrush;
import com.vilyever.drawingview.brush.drawing.IsoscelesTriangleBrush;
import com.vilyever.drawingview.brush.drawing.LineBrush;
import com.vilyever.drawingview.brush.drawing.PenBrush;
import com.vilyever.drawingview.brush.drawing.PolygonBrush;
import com.vilyever.drawingview.brush.drawing.RectangleBrush;
import com.vilyever.drawingview.brush.drawing.RightAngledTriangleBrush;
import com.vilyever.drawingview.brush.drawing.RoundedRectangleBrush;
import com.vilyever.drawingview.brush.drawing.ShapeBrush;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.HomeActivity;
import flc.ast.R;
import flc.ast.adapter.FrameAdapter;
import flc.ast.adapter.PolygonAdapter;
import flc.ast.bean.FrameBean;
import flc.ast.bean.PolygonBean;
import flc.ast.databinding.ActivityDrawBinding;
import flc.ast.utils.Content;
import io.reactivex.rxjava3.core.ObservableEmitter;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.FileUtil;
import stark.common.basic.utils.RxUtil;

public class DrawActivity extends BaseAc<ActivityDrawBinding> implements SeekBar.OnSeekBarChangeListener {

    public static boolean isImitation;
    public static Integer img;
    private Dialog myImageDialog;
    private PenBrush penBrush;
    private ShapeBrush mSelectBrush;
    private String mSelectColor;
    private int paintWidth = 15;//画笔宽度
    private int eraserWidth = 15;//橡皮擦宽度
    private List<PolygonBean> mPolygonBeanList = new ArrayList<>();
    private PolygonAdapter mPolygonAdapter;
    private int tmpPos = 0;

    //颜色
    private static final String COLOR_STRING_FORMAT = "%02x%02x%02x";
    private int red, green, blue;
    private List<FrameBean> mFrameBeanList;
    private int tmpFramePos;
    private FrameAdapter mFrameAdapter;

    //背景颜色
    private int redBg, greenBg, blueBg;
    private List<FrameBean> mFrameBeanBgList;
    private int tmpFrameBgPos;
    private FrameAdapter mFrameBgAdapter;


    @Override
    protected int onCreate() {
        return R.layout.activity_draw;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivDrawBack.setOnClickListener(v -> onBackPressed());

        mSelectColor = "#000000";
        mSelectBrush = PolygonBrush.defaultBrush();

        mDataBinding.ivDrawRevocation.setOnClickListener(this);
        mDataBinding.ivDrawRecover.setOnClickListener(this);
        mDataBinding.ivDrawPaint.setOnClickListener(this);
        mDataBinding.ivDrawEraser.setOnClickListener(this);
        mDataBinding.ivDrawPolygon.setOnClickListener(this);
        mDataBinding.ivDrawBackground.setOnClickListener(this);
        mDataBinding.ivDrawSelectColor.setOnClickListener(this);
        mDataBinding.ivPaintShow.setOnClickListener(this);
        mDataBinding.ivPaintHide.setOnClickListener(this);
        mDataBinding.ivEraserShow.setOnClickListener(this);
        mDataBinding.ivEraserHide.setOnClickListener(this);
        mDataBinding.ivDrawSave.setOnClickListener(this);
        mDataBinding.rlDrawImg.setOnClickListener(this);

        mDataBinding.rvPaintPolygon.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        mPolygonAdapter = new PolygonAdapter();
        mDataBinding.rvPaintPolygon.setAdapter(mPolygonAdapter);
        mPolygonAdapter.setOnItemClickListener(this);

        mDataBinding.myDrawingView.setUndoRedoStateDelegate(new DrawingView.UndoRedoStateDelegate() {
            @Override
            public void onUndoRedoStateChange(DrawingView drawingView, boolean canUndo, boolean canRedo) {
                if (canUndo) {
                    mDataBinding.ivDrawRevocation.setImageResource(R.drawable.aqianche);
                } else {
                    mDataBinding.ivDrawRevocation.setImageResource(R.drawable.aqianchewu);
                }
                if (canRedo) {
                    mDataBinding.ivDrawRecover.setImageResource(R.drawable.ahouchey);
                } else {
                    mDataBinding.ivDrawRecover.setImageResource(R.drawable.ahouche);
                }
            }
        });
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivDrawRecover:  // 复原
                mDataBinding.myDrawingView.redo();
                break;
            case R.id.ivDrawRevocation:  // 撤回
                mDataBinding.myDrawingView.undo();
                break;
            case R.id.ivDrawPaint://画笔
                clearSelection();
                penBrush.setIsEraser(false);
                penBrush.setSize(paintWidth);
                mDataBinding.myDrawingView.setBrush(penBrush);
                mDataBinding.ivDrawPaint.setImageResource(R.drawable.axuanzhb);
                mDataBinding.rlPaint.setVisibility(View.VISIBLE);
                break;
            case R.id.ivDrawEraser://橡皮
                clearSelection();
                penBrush.setIsEraser(true);
                penBrush.setSize(eraserWidth);
                mDataBinding.myDrawingView.setBrush(penBrush);
                mDataBinding.ivDrawEraser.setImageResource(R.drawable.axuanzxp);
                mDataBinding.rlEraser.setVisibility(View.VISIBLE);
                break;
            case R.id.ivDrawPolygon://形状
                clearSelection();
                mDataBinding.ivDrawPolygon.setImageResource(R.drawable.axingzxz);
                mDataBinding.llPolygon.setVisibility(View.VISIBLE);
                break;
            case R.id.ivDrawBackground://背景颜色
                clearSelection();
                mDataBinding.ivDrawBackground.setImageResource(R.drawable.abeijxz);
                mDataBinding.llBgColor.setVisibility(View.VISIBLE);
                break;
            case R.id.ivBgColorConfirm://背景颜色确定
                String content = mDataBinding.etBgColorContent.getText().toString();
                if (TextUtils.isEmpty(content)) {
                    ToastUtils.showShort(R.string.et_color_tips);
                    return;
                }
                if (content.length() < 6) {
                    ToastUtils.showShort(R.string.color_tips2);
                    return;
                }
                String color = "#" + content;
                mDataBinding.rlDrawSave.setBackgroundColor(Color.parseColor(color));
                mDataBinding.llBgColor.setVisibility(View.GONE);
                break;
            case R.id.ivDrawSelectColor://选择颜色
                clearSelection();
                mDataBinding.llColor.setVisibility(View.VISIBLE);
                break;
            case R.id.ivColorConfirm://颜色确定
                String content1 = mDataBinding.etColorContent.getText().toString();
                if (TextUtils.isEmpty(content1)) {
                    ToastUtils.showShort(R.string.et_color_tips);
                    return;
                }
                if (content1.length() < 6) {
                    ToastUtils.showShort(R.string.color_tips2);
                    return;
                }
                mSelectColor = "#" + content1;
                penBrush.setColor(Color.parseColor(mSelectColor));
                mSelectBrush.setColor(Color.parseColor(mSelectColor));
                mDataBinding.crlColorBg.setColor(Color.parseColor(mSelectColor));
                mDataBinding.llColor.setVisibility(View.GONE);
                break;
            case R.id.ivPaintShow://画笔显示
                mDataBinding.llPaint.setVisibility(View.VISIBLE);
                mDataBinding.llPaintShow.setVisibility(View.GONE);
                break;
            case R.id.ivPaintHide://画笔隐藏
                mDataBinding.llPaint.setVisibility(View.GONE);
                mDataBinding.llPaintShow.setVisibility(View.VISIBLE);
                break;
            case R.id.ivEraserShow://橡皮显示
                mDataBinding.llEraser.setVisibility(View.VISIBLE);
                mDataBinding.llEraserShow.setVisibility(View.GONE);
                break;
            case R.id.ivEraserHide://橡皮隐藏
                mDataBinding.llEraser.setVisibility(View.GONE);
                mDataBinding.llEraserShow.setVisibility(View.VISIBLE);
                break;
            case R.id.ivDrawSave://保存
                saveImg();
                break;
            case R.id.rlDrawImg://临摹图片
                myImageDialog.show();
                break;
        }
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        if (adapter == mFrameAdapter) {
            FrameBean item = mFrameAdapter.getItem(position);
            mFrameAdapter.getItem(tmpFramePos).setSelected(false);
            item.setSelected(true);
            tmpFramePos = position;
            mFrameAdapter.notifyDataSetChanged();

            mDataBinding.etColorContent.setText(item.getFrameColor().replace("#", ""));
            mDataBinding.llColorView.setBackgroundColor(Color.parseColor(item.getFrameColor()));

            mSelectColor = item.getFrameColor();
            penBrush.setColor(Color.parseColor(mSelectColor));
            mSelectBrush.setColor(Color.parseColor(mSelectColor));
            mDataBinding.crlColorBg.setColor(Color.parseColor(mSelectColor));
            mDataBinding.llColor.setVisibility(View.GONE);
        } else if (adapter == mFrameBgAdapter) {
            FrameBean item = mFrameBgAdapter.getItem(position);
            mFrameBgAdapter.getItem(tmpFrameBgPos).setSelected(false);
            item.setSelected(true);
            tmpFrameBgPos = position;
            mFrameBgAdapter.notifyDataSetChanged();

            mDataBinding.etBgColorContent.setText(item.getFrameColor().replace("#", ""));
            mDataBinding.llBgColorView.setBackgroundColor(Color.parseColor(item.getFrameColor()));

            mDataBinding.rlDrawSave.setBackgroundColor(Color.parseColor(item.getFrameColor()));
            mDataBinding.llBgColor.setVisibility(View.GONE);
        } else if (adapter == mPolygonAdapter) {
            mPolygonAdapter.getItem(tmpPos).setSelected(false);
            mPolygonAdapter.notifyItemChanged(tmpPos);
            tmpPos = position;
            mPolygonAdapter.getItem(position).setSelected(true);
            mPolygonAdapter.notifyItemChanged(position);
            mSelectBrush = mPolygonAdapter.getItem(position).getShapeBrush();
            mSelectBrush.setColor(Color.parseColor(mSelectColor));
            mSelectBrush.setSize(15);
            mDataBinding.myDrawingView.setBrush(mSelectBrush);
        }
    }

    @Override
    protected void initData() {
        if (isImitation) {
            mDataBinding.ivDrawImg.setImageResource(img);
            mDataBinding.rlDrawImg.setVisibility(View.VISIBLE);
            mDataBinding.tvDrawTitle.setText(R.string.imitation_drawing_board);
            //图片弹框
            imageDialog();
        } else {
            mDataBinding.tvDrawTitle.setText(R.string.free_drawing_board);
        }

        //初始化画笔
        initPen();
        mPolygonBeanList.add(new PolygonBean(PolygonBrush.defaultBrush(), R.drawable.amoren));
        mPolygonBeanList.add(new PolygonBean(RectangleBrush.defaultBrush(), R.drawable.azhenfangx));
        mPolygonBeanList.add(new PolygonBean(IsoscelesTriangleBrush.defaultBrush(), R.drawable.asanjiaox));
        mPolygonBeanList.add(new PolygonBean(CircleBrush.defaultBrush(), R.drawable.ayuanx));
        mPolygonBeanList.add(new PolygonBean(EllipseBrush.defaultBrush(), R.drawable.atuoyuan));
        mPolygonBeanList.add(new PolygonBean(RoundedRectangleBrush.defaultBrush(), R.drawable.azhijsjx));
        mPolygonBeanList.add(new PolygonBean(RightAngledTriangleBrush.defaultBrush(), R.drawable.azhijiaosjx));
        mPolygonBeanList.add(new PolygonBean(LineBrush.defaultBrush(), R.drawable.azhixian));

        mPolygonBeanList.get(tmpPos).setSelected(true);
        mPolygonAdapter.setList(mPolygonBeanList);

        //初始化颜色选择
        initColor();
        //初始化背景颜色选择
        initBgColor();
    }

    //初始化画笔
    private void initPen() {
        penBrush = PenBrush.defaultBrush();
        penBrush.setColor(Color.parseColor("#000000"));//默认画笔颜色
        penBrush.setSize(15);//默认画笔大小
        mDataBinding.myDrawingView.setBrush(penBrush);
        //设置画笔大小
        mDataBinding.seekbarBrush.setMax(50);
        mDataBinding.seekbarBrush.setProgress(5);
        mDataBinding.seekbarBrush.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                //画笔擦大小
                paintWidth = 5 + i * 2;
                penBrush.setSize(paintWidth);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        //设置橡皮擦大小
        mDataBinding.seekbarEraser.setMax(50);
        mDataBinding.seekbarEraser.setProgress(5);
        mDataBinding.seekbarEraser.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                //画笔擦大小
                eraserWidth = 5 + i * 2;
                penBrush.setSize(eraserWidth);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

    //初始化颜色选择
    private void initColor() {
        red = 255;
        green = 0;
        blue = 0;
        mFrameBeanList = new ArrayList<>();
        tmpFramePos = 0;

        mDataBinding.redSeekBar.setProgress(red);
        mDataBinding.greenSeekBar.setProgress(green);
        mDataBinding.blueSeekBar.setProgress(blue);

        mDataBinding.llColorView.setBackgroundColor(Color.rgb(red, green, blue));

        mDataBinding.etColorContent.setText(String.format(COLOR_STRING_FORMAT, red, green, blue));

        mDataBinding.ivColorConfirm.setOnClickListener(this);
        mDataBinding.redSeekBar.setOnSeekBarChangeListener(this);
        mDataBinding.greenSeekBar.setOnSeekBarChangeListener(this);
        mDataBinding.blueSeekBar.setOnSeekBarChangeListener(this);
        mDataBinding.etColorContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() == 6) {
                    mDataBinding.llColorView.setBackgroundColor(Color.parseColor("#" + String.format(COLOR_STRING_FORMAT, red, green, blue)));
                }
            }
        });

        mDataBinding.rvColor.setLayoutManager(new GridLayoutManager(mContext, 8));
        mFrameAdapter = new FrameAdapter();
        mDataBinding.rvColor.setAdapter(mFrameAdapter);
        mFrameAdapter.setOnItemClickListener(this);

        getFrameData();
    }

    //初始化背景颜色选择
    private void initBgColor() {
        redBg = 255;
        greenBg = 0;
        blueBg = 0;
        mFrameBeanBgList = new ArrayList<>();
        tmpFrameBgPos = 0;

        mDataBinding.redBgSeekBar.setProgress(redBg);
        mDataBinding.greenBgSeekBar.setProgress(greenBg);
        mDataBinding.blueBgSeekBar.setProgress(blueBg);

        mDataBinding.llBgColorView.setBackgroundColor(Color.rgb(redBg, greenBg, blueBg));

        mDataBinding.etBgColorContent.setText(String.format(COLOR_STRING_FORMAT, redBg, greenBg, blueBg));

        mDataBinding.ivBgColorConfirm.setOnClickListener(this);
        mDataBinding.redBgSeekBar.setOnSeekBarChangeListener(this);
        mDataBinding.greenBgSeekBar.setOnSeekBarChangeListener(this);
        mDataBinding.blueBgSeekBar.setOnSeekBarChangeListener(this);
        mDataBinding.etBgColorContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() == 6) {
                    mDataBinding.llBgColorView.setBackgroundColor(Color.parseColor("#" + String.format(COLOR_STRING_FORMAT, redBg, greenBg, blueBg)));
                }
            }
        });

        mDataBinding.rvBgColor.setLayoutManager(new GridLayoutManager(mContext, 8));
        mFrameBgAdapter = new FrameAdapter();
        mDataBinding.rvBgColor.setAdapter(mFrameBgAdapter);
        mFrameBgAdapter.setOnItemClickListener(this);

        getFrameBgData();
    }

    private void getFrameData() {
        mFrameBeanList.add(new FrameBean("#FFFFFF"));
        mFrameBeanList.add(new FrameBean("#000000"));
        mFrameBeanList.add(new FrameBean("#FFDF8D"));
        mFrameBeanList.add(new FrameBean("#3A52BD"));
        mFrameBeanList.add(new FrameBean("#9BA9DE"));
        mFrameBeanList.add(new FrameBean("#00B8AB"));
        mFrameBeanList.add(new FrameBean("#63CDC3"));
        mFrameBeanList.add(new FrameBean("#CDA163"));
        mFrameBeanList.add(new FrameBean("#FF6159"));
        mFrameBeanList.add(new FrameBean("#FF5592"));
        mFrameBeanList.add(new FrameBean("#D990DE"));
        mFrameBeanList.add(new FrameBean("#8455C7"));
        mFrameBeanList.add(new FrameBean("#4C78FF"));
        mFrameBeanList.add(new FrameBean("#00E9FF"));
        mFrameBeanList.add(new FrameBean("#BEE29E"));
        mFrameBeanList.add(new FrameBean("#9AFFDA"));

        mFrameAdapter.setList(mFrameBeanList);
    }

    private void getFrameBgData() {
        mFrameBeanBgList.add(new FrameBean("#FFFFFF"));
        mFrameBeanBgList.add(new FrameBean("#000000"));
        mFrameBeanBgList.add(new FrameBean("#FFDF8D"));
        mFrameBeanBgList.add(new FrameBean("#3A52BD"));
        mFrameBeanBgList.add(new FrameBean("#9BA9DE"));
        mFrameBeanBgList.add(new FrameBean("#00B8AB"));
        mFrameBeanBgList.add(new FrameBean("#63CDC3"));
        mFrameBeanBgList.add(new FrameBean("#CDA163"));
        mFrameBeanBgList.add(new FrameBean("#FF6159"));
        mFrameBeanBgList.add(new FrameBean("#FF5592"));
        mFrameBeanBgList.add(new FrameBean("#D990DE"));
        mFrameBeanBgList.add(new FrameBean("#8455C7"));
        mFrameBeanBgList.add(new FrameBean("#4C78FF"));
        mFrameBeanBgList.add(new FrameBean("#00E9FF"));
        mFrameBeanBgList.add(new FrameBean("#BEE29E"));
        mFrameBeanBgList.add(new FrameBean("#9AFFDA"));

        mFrameBgAdapter.setList(mFrameBeanBgList);
    }

    //保存图片
    private void saveImg() {
        showDialog(getString(R.string.saving));
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                RxUtil.create(new RxUtil.Callback<String>() {

                    @Override
                    public void doBackground(ObservableEmitter<String> emitter) {
                        Bitmap bitmap = ImageUtils.view2Bitmap(mDataBinding.rlDrawSave);
                        //保存到相册
                        ImageUtils.save2Album(bitmap, Bitmap.CompressFormat.PNG);
                        //保存到历史记录
                        String filePath = FileUtil.generateFilePath(Content.myDrawRecord, ".png");
                        ImageUtils.save(bitmap, filePath, Bitmap.CompressFormat.PNG);
                        emitter.onNext("");
                    }

                    @Override
                    public void accept(String path) {
                        dismissDialog();
                        ToastUtils.showShort(R.string.save_success);
                        startActivity(HomeActivity.class);
                    }
                });
            }
        }, 1000);
    }

    //图片弹框
    private void imageDialog() {
        myImageDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_img, null);
        myImageDialog.setContentView(inflate);
        myImageDialog.setCancelable(true);
        Window dialogWindow = myImageDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.9);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        ImageView imageView = inflate.findViewById(R.id.ivDialogImg);
        imageView.setImageResource(img);
    }

    private void clearSelection() {
        mDataBinding.ivDrawPaint.setImageResource(R.drawable.ahuabi);
        mDataBinding.ivDrawEraser.setImageResource(R.drawable.axiangpic);
        mDataBinding.ivDrawPolygon.setImageResource(R.drawable.axingzhuang);
        mDataBinding.ivDrawBackground.setImageResource(R.drawable.abeij);
        mDataBinding.rlPaint.setVisibility(View.GONE);
        mDataBinding.rlEraser.setVisibility(View.GONE);
        mDataBinding.llPolygon.setVisibility(View.GONE);
        mDataBinding.llColor.setVisibility(View.GONE);
        mDataBinding.llBgColor.setVisibility(View.GONE);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (seekBar.getId() == R.id.redSeekBar) {
            red = progress;
            mDataBinding.redToolTip.setText(red + "");
            mDataBinding.llColorView.setBackgroundColor(Color.rgb(red, green, blue));
            mDataBinding.etColorContent.setText(String.format(COLOR_STRING_FORMAT, red, green, blue));
        } else if (seekBar.getId() == R.id.greenSeekBar) {
            green = progress;
            mDataBinding.greenToolTip.setText(green + "");
            mDataBinding.llColorView.setBackgroundColor(Color.rgb(red, green, blue));
            mDataBinding.etColorContent.setText(String.format(COLOR_STRING_FORMAT, red, green, blue));
        } else if (seekBar.getId() == R.id.blueSeekBar) {
            blue = progress;
            mDataBinding.blueToolTip.setText(blue + "");
            mDataBinding.llColorView.setBackgroundColor(Color.rgb(red, green, blue));
            mDataBinding.etColorContent.setText(String.format(COLOR_STRING_FORMAT, red, green, blue));
        } else if (seekBar.getId() == R.id.redBgSeekBar) {
            redBg = progress;
            mDataBinding.redBgToolTip.setText(redBg + "");
            mDataBinding.llBgColorView.setBackgroundColor(Color.rgb(redBg, greenBg, blueBg));
            mDataBinding.etBgColorContent.setText(String.format(COLOR_STRING_FORMAT, redBg, greenBg, blueBg));
        } else if (seekBar.getId() == R.id.greenBgSeekBar) {
            greenBg = progress;
            mDataBinding.greenBgToolTip.setText(greenBg + "");
            mDataBinding.llBgColorView.setBackgroundColor(Color.rgb(redBg, greenBg, blueBg));
            mDataBinding.etBgColorContent.setText(String.format(COLOR_STRING_FORMAT, redBg, greenBg, blueBg));
        } else if (seekBar.getId() == R.id.blueBgSeekBar) {
            blueBg = progress;
            mDataBinding.blueBgToolTip.setText(blueBg + "");
            mDataBinding.llBgColorView.setBackgroundColor(Color.rgb(redBg, greenBg, blueBg));
            mDataBinding.etBgColorContent.setText(String.format(COLOR_STRING_FORMAT, redBg, greenBg, blueBg));
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
}